package com.tanhua.server.controller;

import com.tanhua.server.service.PeachService;
import com.tanhua.server.vo.PeachSoundVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @description:
 * @author: Administrator
 * @date: Created in 2021年3月6日18:08:47
 * @version: 0.0.1
 * @modified By:
 */
@RestController
@RequestMapping("peachblossom")
public class PeachController {

    @Autowired
    private PeachService peachService;
    /**
     * @description 发送语音
     * @author
     * @date
     * @param
     *@return
     */
    @PostMapping
    public ResponseEntity<Void>savePeach(@RequestParam("soundFile")MultipartFile soundFile){
        try {
            Boolean bool= this.peachService.savePeach(soundFile);
            if(bool){
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
    /**
     * @description 接收语音
     * @author
     * @date
     * @param
     *@return
     */
    @GetMapping()
    public ResponseEntity<PeachSoundVo>receiveSound(){
        try {
            PeachSoundVo peachSoundVo=this.peachService.receiveSound();
            if(null!=peachSoundVo){
                return ResponseEntity.ok(peachSoundVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

}
